/* $Header: scc_ui.c,v 2.2 01/10/02 10:33:02 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1992                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:  scc_ui.c                                              */
/* ============                                                        */
/*                                                                     */
/* Author:  Lesley Freed                                               */
/*                                                                     */
/* MODULE PURPOSE:  To provide the Set, Get, and Check functions for   */
/*                  the user interface to the scc parameters.          */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <ramps.h>
#include <zone_config.h>
#include <zone_status.h>
#include <status.h>
#include <error.h>
#include <sig_types.h>
#include <sig_ui.h>

#include <exception.h>
#include <glp.h>

#include <p_status.h>
#include <det_ui.h>
#include <clock_ui.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/


/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/



/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

SCC_COLLECT_STATE GetSccCollectState( pCCOMP_TABLE pccomp )
{
   if ( pccomp->collect_scc_flag == 1 )
   {
      if ( Scc_Run && (Run_State == RUN_ACTIVE) )
      {
         return ( COLLECT_ON );
      }
      else
      {
         return ( COLLECT_WAIT );
      }
   }
   else
   {
      return ( COLLECT_OFF );
   }
}


/* Return the position for which the scc profile was stored */

POSITION GetSccDataDetector( pCCOMP_TABLE pccomp )
{
   return( pccomp->pdata->det_data_stored );
}

/* Return the detector type for which the scc profile was stored */

DET_TYPE GetSccDetectorType( pCCOMP_TABLE pccomp )
{
   return( pccomp->pdata->det_type );
}


/* See if we can change the detector position for collecting the next scc     */
/* profile.                                                                   */

UI_ERR CheckSccSignalType( pCCOMP_TABLE pccomp, POSITION position )
{
   SCC_COLLECT_STATE state;

   state = GetSccCollectState( pccomp );

   if ( state != COLLECT_OFF )
   {
      return( NOT_VALID_DURING_SCC_RUN );
   }

   if ( position == NULL_POSITION )
   {
      return OK;
   }

   if ( GetDetectorType( position ) == NO_DET )
   {
      return( NOT_INSTALLED );
   }

   return( OK );
}

/* Set the detector position for collecting the next scc profile */

UI_ERR SetSccSignalType( pCCOMP_TABLE pccomp, POSITION position )
{
   UI_ERR check_setpt;
   SETPT  setpt_no;

   check_setpt = CheckSccSignalType( pccomp, position );

   if ( check_setpt != OK ) return check_setpt;

   if ( pccomp == pCCOMP1 )
   {
      Active_Wkfile.col_comp1_det = position;
      setpt_no = COL_COMP1_DET_POSITION;
   }
   else
   {
      Active_Wkfile.col_comp2_det = position;
      setpt_no = COL_COMP2_DET_POSITION;
   }

   LogSetptChange( setpt_no, (INT32)position, 0 );

   return( OK );
}

POSITION GetSccSignalType( pCCOMP_TABLE pccomp )
{
   if ( pccomp == pCCOMP1 )
   {
      return ( Active_Wkfile.col_comp1_det );
   }

   return ( Active_Wkfile.col_comp2_det );
}

SCC_DATA_STATE GetSccDataState( pCCOMP_TABLE pccomp )
{
   return ( pccomp->pdata->data_valid_flag );
}


DATETIME GetSccDataDateTime (pCCOMP_TABLE pccomp )
{
   return pccomp->pdata->datetime;
}

INT32 GetSccDataDate (pCCOMP_TABLE pccomp )
{
   return GetDate( &(pccomp->pdata->datetime) );
}

INT32 GetSccDataTime (pCCOMP_TABLE pccomp )
{
   return GetTime( &(pccomp->pdata->datetime) );
}

